<template>
  <vue-content>
    <vue-header>
      <div style="float:right">
        <vue-header-form class="headerFrom">
          <el-form :inline="true" :model="formFilter" ref="formFilter">
            <el-form-item>
                <el-button @click="exportForm('formFilter')">导出</el-button>
            </el-form-item>
          </el-form>
        </vue-header-form>
      </div>
    </vue-header>
    <vue-body>
      <el-table
      	v-loading.body="loading"
        :data="tableData"
        border
        style="width: 100%">
        <el-table-column
          prop="couponName"
          label="	核销优惠券名称">
        </el-table-column>
        <el-table-column
          prop="verificationUserName"
          label="核销人">
        </el-table-column>
        <el-table-column
          prop="verificationUserPhone"
          label="核销手机号">
        </el-table-column>
        <el-table-column
          prop="storeName"
          label="核销店铺名称">
        </el-table-column>
        <el-table-column
          prop="storeUserName"
          label="核销店员名称">
        </el-table-column>
        <el-table-column
          prop="storeUserPhone"
          label="核销店员手机号">
        </el-table-column>
        <el-table-column
          prop="createDate"
          label="	核销时间">
        </el-table-column>
        <el-table-column
          label="核销状态">
          <template slot-scope="scope">
            {{ scope.row.status | status }}
          </template>
        </el-table-column>
      </el-table>
    </vue-body>
     <vue-footer style="padding: 5px 0;margin: 0 -5px;float:right;">
      <el-pagination
        :current-page.sync="currentPage"
        :page-size="10"
        layout="total, prev, pager, next"
        :total="pageSize">
      </el-pagination>
    </vue-footer>
    <div class="back">
      <el-button type="info" class="insProbtn" @click="back()">后退</el-button>
    </div>
  </vue-content>
</template>

<script>
  import AuthStorage from '@/services/storage.js'
  import { md5 } from '@/utilities/crypto' // 加密
  import {queryVerification} from '@/services/reports'
  import {RequestError} from '@/services/errors'
  import {deepClone} from '@/utilities/object'
  export default {
    name: 'sp-opera',
    components: {},
    data: () => ({
      tableData: [],
      currentPage: 1,
      pageSize: 10,
      formFilter: {
      },
      loading: false,
      CategoryList:[],
      view: '',
      ifShow:false
    }),
    methods: {
      async loadData () {
        this.loading = true
        try {
          let data = await queryVerification(Object.assign({currentPage: this.currentPage},{perPage:10},this.formFilter))
          // debugger
          this.tableData = data.data
          this.pageSize = parseInt(data.totalResult)
        } catch (e) {
          if (e instanceof RequestError) {
            this.$alert(e.message, '提示', {
              type: 'error',
              confirmButtonText: '确定'
            })
          } else {
            throw e
          }
        }
        this.loading = false
      },
      exportForm(){
        this.exportData();
      },
      async exportData () {
        var param=Object.assign({currentPage: this.currentPage},{perPage:10},this.formFilter);
        var  a = new Date();
        var btime= a .getTime();
        var signs2 = "data="+JSON.stringify(param)+"&stmb="+btime;
        this.postDownLoadFile({
          url:this.$store.state.exportUrl + 'ecshop/verification/verificationCouponExport.do?stmb='+ a.getTime() +'&source="03"&token='+ AuthStorage.token +'&version=""&data='+JSON.stringify(param)+'&sign='+this.signature(signs2),
          method:'post'
        });
      },
      postDownLoadFile(options) {
          var config = $.extend(true, { method: 'post' }, options);
          var $iframe = $('<iframe id="down-file-iframe" />');
          var $form = $('<form target="down-file-iframe" method="' + config.method + '" />');
          $form.attr('action', config.url);
          for (var key in config.data) {
              $form.append('<input type="hidden" name="' + key + '" value="' + config.data[key] + '" />');
          }
          $iframe.append($form);
          $(document.body).append($iframe);
          $form[0].submit();
          $iframe.remove();
      },
      signature(data) {
        return md5(data)
      },
      back(){
        this.$router.go(-1)
      }
    },
    watch: {
      currentPage (newVal) {
        this.loadData(newVal)
      }
    },
    filters: {
      status (value) {
      	//发券途径
        return {'00': '未核销','01': '已核销'}[value]
      },
    },
    created () {
      this.loadData()
    }
  }
</script>

<style>
  .back{
    width: 100%;
    overflow: hidden;
    padding-top: 10px;
  }
</style>

